package com.clarence.dada.modular.system.user.controller;

import com.clarence.dada.core.base.BaseReq;
import com.clarence.dada.core.base.PageResult;
import com.clarence.dada.core.base.Result;
import com.clarence.dada.modular.system.user.entity.req.SysUserReq;
import com.clarence.dada.modular.system.user.entity.resp.SysUserResp;
import com.clarence.dada.modular.system.user.service.SysUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 系统用户控制器
 * <p>
 *
 * @author <a href="mailto:1093776034@qq.com">GD</a>
 * @since 2024/01/30 23:06
 */
@RestController
@RequestMapping("/system/sysUser/")
@Tag(name = "用户管理", description = "用户管理Controller")
public class SysUserController {
    @Resource
    private SysUserService sysUserService;

    /**
     * 增加用户
     *
     * @author GD
     * @since 2020/11/6 13:50
     */
    @Operation(summary = "系统用户_增加", description = "增加用户")
    @PostMapping("userAdd")
    public Result<Void> userAdd(@RequestBody @Validated(BaseReq.add.class) SysUserReq sysUserReq) {
        sysUserService.userAdd(sysUserReq);
        return Result.SUCCESS;
    }

    /**
     * 删除系统用户
     *
     * @author GD
     * @since 2020/11/6 13:50
     */
    @Operation(summary = "系统用户_删除", description = "删除用户")
    @PostMapping("userDelete")
    public Result<Void> userDelete(@RequestBody @Validated(SysUserReq.delete.class) SysUserReq sysUserReq) {
        sysUserService.userDelete(sysUserReq);
        return Result.SUCCESS;
    }

    /**
     * 编辑系统用户
     *
     * @author GD
     * @since 2020/11/6 13:50
     */
    @Operation(summary = "系统用户_编辑", description = "编辑用户")
    @PostMapping("userEdit")
    public Result<Void> userEdit(@RequestBody @Validated(SysUserReq.edit.class) SysUserReq sysUserReq) {
        sysUserService.userEdit(sysUserReq);
        return Result.SUCCESS;
    }

    /**
     * 修改状态
     *
     * @author GD
     * @since 2020/11/6 13:50
     */
    @Operation(summary = "系统用户_修改状态", description = "修改用户状态")
    @PostMapping("userUpdateStatus")
    public Result<Void> userUpdateStatus(@RequestBody @Validated(SysUserReq.changeStatus.class) SysUserReq sysUserReq) {
        sysUserService.userUpdateStatus(sysUserReq);
        return Result.SUCCESS;

    }

    /**
     * 重置密码
     *
     * @author GD
     * @since 2020/11/6 13:48
     */
    @Operation(summary = "系统用户_重置密码", description = "重置用户密码")
    @PostMapping("userResetPassword")
    public Result<Void> userResetPassword(@RequestBody @Validated(SysUserReq.resetPwd.class) SysUserReq sysUserReq) {
        sysUserService.userResetPassword(sysUserReq);
        return Result.SUCCESS;

    }

    /**
     * 授权角色
     *
     * @author GD
     * @since 2020/11/6 13:50
     */
    @Operation(summary = "系统用户_授权角色", description = "授权用户角色")
    @PostMapping("userGrantRole")
    public Result<Void> userGrantRole(@RequestBody @Validated(SysUserReq.grantRole.class) SysUserReq sysUserReq) {
//        sysUserService.grantRole(sysUserVo);
        return Result.SUCCESS;
    }

    /**
     * 查看系统用户
     *
     * @author GD
     * @since 2020/11/6 13:50
     */
    @Operation(summary = "系统用户_查看", description = "查看用户")
    @GetMapping("userDetail")
    public Result<SysUserResp> userDetail(@Validated(SysUserReq.detail.class) SysUserReq sysUserReq) {
        return new Result<>(sysUserService.userDetail(sysUserReq));
    }
//
//    /**
//     * 获取当前登录用户的信息
//     *
//     * @author GD
//     * @since 2021/1/1 19:01
//     */
//    @Operation(summary= "获取当前登录用户的信息", description = "获取当前登录用户的信息")
//    @GetMapping("currentUserInfo")
//    public Result<SysUserDto> currentUserInfo() {
//        LoginUser loginUser = LoginContext.me().getLoginUser();
//
//        SysUserVo SysUserVo = new SysUserVo();
//        SysUserVo.setUserId(loginUser.getUserId());
//        return new Result<>(sysUserService.detail(SysUserVo));
//    }

    /**
     * 查询系统用户
     *
     * @author GD
     * @since 2020/11/6 13:49
     */
    @Operation(summary = "系统用户_查询列表（分页）")
    @GetMapping("userPage")
    public Result<PageResult<SysUserResp>> userPage(SysUserReq sysUserReq) {
        return new Result<>(sysUserService.userPage(sysUserReq));
    }

}
